Skip to content

Python: Add GitHub Copilot BYOK sample - #7336

Merged
eavanvalkenburg merged 3 commits into
microsoft:mainfrom
droideronline:sample/github-copilot-byok-python
Jul 30, 2026
Merged

Python: Add GitHub Copilot BYOK sample#7336
eavanvalkenburg merged 3 commits into
microsoft:mainfrom
droideronline:sample/github-copilot-byok-python

Conversation

@droideronline

Copy link
Copy Markdown
Contributor

Motivation & Context

GitHub Copilot supports BYOK (Bring Your Own Key — https://docs.github.com/en/copilot/how-tos/copilot-sdk/auth/byok), letting requests be routed through a custom OpenAI/Azure/Anthropic-compatible endpoint instead of the default GitHub Copilot backend. GitHubCopilotOptions.provider already forwards a ProviderConfig straight through to the Copilot SDK, but there was no sample demonstrating the scenario end-to-end.

Description & Review Guide

  • What are the major changes? Adds github_copilot_with_byok.py under python/samples/02-agents/providers/github_copilot/, showing how to set GitHubCopilotOptions(model=..., provider=ProviderConfig(...)) to route through a custom endpoint, reading BYOK_BASE_URL/BYOK_API_KEY/BYOK_MODEL_ID from the environment. Updates the folder's README.md table to list the new sample.
  • What is the impact of these changes? Documentation/sample only — no changes to library code.
  • What do you want reviewers to focus on? Whether the ProviderConfig fields used (type, base_url, api_key, wire_api, model_id) match current guidance, and whether the security note on static BYOK credentials is clear enough.

Verified with ruff check, ruff format --check, and pyright (all clean).

Related Issue

Fixes #

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

Demonstrates routing GitHubCopilotAgent requests through a custom OpenAI-compatible
endpoint via ProviderConfig instead of the default GitHub Copilot backend.
Copilot AI review requested due to automatic review settings July 26, 2026 17:49
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jul 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Python sample demonstrating how to use GitHubCopilotAgent with Copilot SDK BYOK (Bring Your Own Key) to route requests through a custom OpenAI/Azure/Anthropic-compatible endpoint, and documents it in the provider samples README.

Changes:

  • Add github_copilot_with_byok.py sample showing BYOK configuration via GitHubCopilotOptions(provider=...) and environment variables.
  • Update the GitHub Copilot provider samples README.md to include the new sample in the examples table.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
python/samples/02-agents/providers/github_copilot/README.md Adds the BYOK sample to the examples list for discoverability.
python/samples/02-agents/providers/github_copilot/github_copilot_with_byok.py New end-to-end sample configuring BYOK provider routing and model selection via env vars.
Comments suppressed due to low confidence (1)

python/samples/02-agents/providers/github_copilot/github_copilot_with_byok.py:41

  • The sample hard-codes type: "openai" while the docstring claims Azure OpenAI/Anthropic are supported, and it also passes model_id inside ProviderConfig (the repo’s existing ProviderConfig examples/tests only use keys like type, base_url, api_key/bearer_token). This is likely to be rejected by the Copilot SDK or confuse users; keep the model selection at GitHubCopilotOptions(model=...) and let the provider type be configurable.
        "type": "openai",
        "base_url": os.environ["BYOK_BASE_URL"],
        "api_key": os.environ["BYOK_API_KEY"],
        "wire_api": "completions",
        "model_id": model_id,

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Make the provider type configurable via BYOK_PROVIDER_TYPE (default "openai") instead
  of hardcoding "openai" — a partial autofix commit had already updated the docstring to
  document this env var but left the code hardcoded, which this finishes.
- Stop calling the endpoint "OpenAI-compatible" everywhere; Anthropic isn't OpenAI-wire-
  compatible, so reword to "your own endpoint" and list the actual supported providers
  (mirrors the equivalent .NET sample fix).
@droideronline

Copy link
Copy Markdown
Contributor Author

@moonbox3 @eavanvalkenburg - kindly take a look when you get a chance, Thanks!

@eavanvalkenburg
eavanvalkenburg added this pull request to the merge queue Jul 30, 2026
Merged via the queue into microsoft:main with commit d42c78c Jul 30, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants